// pages/activity/personal.js
import { Activity } from '../../model/activity';
const appInst =  getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    hidden: false,
    info: null,
    pay_loading: false,
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getGrActivityInfo(options.id);
  },
  /**
   * 获取个人活动详情
   */
  async getGrActivityInfo(id) {
      const res = await Activity.getGrActivityInfo(id);
      this.setData({
        info: res,
        hidden: true,
      })
  },
  /**
   * 创建订单
   */
  async createOrder() {
    this.setData({
      pay_loading: true,
    })
    const res = await Activity.createGrActivityOrder( this.data.info.id);
    if(res) {
      appInst.globalData.pagesgo = './activity';
      appInst.successPay("下车成功");
    } else {
      this.setData({
        pay_loading: false,
      })
    }
  },
  /**
   * 下车操作
   */
  async deleteOrder(){
    this.setData({
      pay_loading: true,
    })
    const res = await Activity.deleteGrActivityOrder( this.data.info.order_id);
    if(res) {
      appInst.globalData.pagesgo = './activity';
      appInst.successPay("下车成功");
    } else {
      this.setData({
        pay_loading: false,
      })
    }
  }
})